package org.frend.rpc.impl;

import com.alibaba.dubbo.config.annotation.Service;
import org.activiti.engine.task.Task;
import org.frend.rpc.model.TaskModel;
import org.frend.rpc.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service(timeout = 1200000)
public class TaskServiceImpl implements TaskService {

    @Autowired
    private org.activiti.engine.TaskService taskService;

    @Override
    public List<TaskModel> getTaskAssignee(String assignee) {
        List<Task> list = taskService.createTaskQuery().taskAssignee(assignee).list();
        List<TaskModel> taskModelList = new ArrayList<>();
        for(Task task : list){
            TaskModel model = new TaskModel();
            model.setAssignee(task.getAssignee());
            model.setCategory(task.getCategory());
            model.setCreateTime(task.getCreateTime());
            model.setDelegationState(task.getDelegationState());
            model.setDescription(task.getDescription());
            model.setDueDate(task.getDueDate());
            model.setExecutionId(task.getExecutionId());
            model.setFormKey(task.getFormKey());
            model.setId(task.getId());
            model.setName(task.getName());
            model.setOwner(task.getOwner());
            model.setParentTaskId(task.getParentTaskId());
            model.setPriority(task.getPriority());
            model.setProcessDefinitionId(task.getProcessDefinitionId());
            model.setProcessInstanceId(task.getProcessInstanceId());
            model.setProcessVariables(task.getProcessVariables());
            model.setSuspended(task.isSuspended());
            model.setTaskDefinitionKey(task.getTaskDefinitionKey());
            model.setTaskLocalVariables(task.getTaskLocalVariables());
            model.setTenantId(task.getTenantId());
            taskModelList.add(model);
        }
        return taskModelList;
    }
}
